home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / documentation / tutorial / applet / overview / example / LamePrintThread.java < prev    next >
Encoding:
Java Source  |  1997-07-13  |  2.1 KB  |  67 lines

  1. /*
  2.  * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.applet.Applet;
  18. import java.awt.Graphics;
  19. import java.awt.TextArea;
  20.  
  21. public class LamePrintThread extends Applet {
  22.  
  23.     java.awt.TextArea display = new java.awt.TextArea(1, 80);
  24.  
  25.     public void init() {
  26.         //Create the text area and make it uneditable.
  27.         display = new TextArea(1, 80);
  28.         display.setEditable(false);
  29.  
  30.     //Set the layout manager so that the text area 
  31.     //will be as wide as possible.
  32.         setLayout(new java.awt.GridLayout(1,0));
  33.  
  34.     //Add the text area to the applet.
  35.         add(display);
  36.         validate();
  37.  
  38.         addItem("init: " + threadInfo(Thread.currentThread()));
  39.     }
  40.  
  41.     public void start() {
  42.         addItem("start: " + threadInfo(Thread.currentThread()));
  43.     }
  44.  
  45.     public void stop() {
  46.         addItem("stop: " + threadInfo(Thread.currentThread()));
  47.     }
  48.  
  49.     public void destroy() {
  50.         addItem("destroy: " + threadInfo(Thread.currentThread()));
  51.     }
  52.  
  53.     String threadInfo(Thread t) {
  54.         return "thread=" + t.getName() + ", "
  55.                + "thread group=" + t.getThreadGroup().getName();
  56.     }
  57.    
  58.     void addItem(String newWord) {
  59.         System.out.println(newWord);
  60.         display.appendText(newWord + "\n");
  61.         display.repaint();
  62.     }
  63.  
  64.     //DO NOT IMPLEMENT update() and paint()!  Netscape Navigator 2.0
  65.     //for Windows crashes if you do.  
  66. }
  67.